<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_heatMapColorSection"></title>
<script type="text/javascript" exclude="iclient-classic" include="heatmapColorCSS"
        src="../../dist/classic/include-classic.js"></script>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
            border: 1px solid #3473b7;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            width: 300px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }

        .winContent {
            padding: 5px;
            overflow-y: auto;
            height: 500px;

        }

        .popupWindow {
            right: 10px;
            bottom: 5px;
            position: absolute;
            background: #FFF;
            z-index: 9999;
            display: block;
        }

        .winTitle {
            background: #1E90FF;
        }

        label {
            display: block;
            margin-bottom: 5px;
        }

        .lab {
            width: 50%;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_heatMapColorSection"></h5></div>
    <div class='panel-body content'>
        <div class='panel'>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_countsDraw"></span>
                <input type='text' class='form-control' id='heatNums' value='200'/>
            </div>
        </div>
        <div class='panel'>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_radius"></span>
                <input class='form-control' style='width: 50px' value='50' id='heatradius'/>
                <select class='form-control' style='width:auto' id='radiusUnit'>
                    <option value='px'>px</option>
                    <option value='degree'>degree</option>
                </select>
            </div>
        </div>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_startDraw"
               onclick="createHeatPoints()"/>&nbsp; &nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear"
               onclick="clearHeatPoints()"/>
    </div>
</div>
<div id="popupWin" class="panel panel-primary popupWindow">
    <div class="winTitle">
        <span class="title_left" data-i18n="resources.text_colorSection"></span>
    </div>
    <div class="winContent" style="overflow-y:auto;height:250px;">
        <table>
            <tbody>
            <tr>
                <td data-i18n="resources.text_temperatureRange" style="padding-right: 25px;padding-left: 5px;"></td>
                <td data-i18n="resources.text_colorGrad" style="padding-right:10px;padding-left: 20px;"> </td>
            </tr>
            </tbody>
        </table>
        <div style="height: 21px;">
            <label class="lab">17--18</label>

            <div class="ex" id="ex1" data-i18n="[style]resources.set_style"></div>
        </div>
        <div style="height: 21px;">
            <label class="lab">18--19</label>

            <div class="ex" id="ex2" data-i18n="[style]resources.set_style"></div>
        </div>
        <div style="height: 21px;">
            <label class="lab">19--20</label>

            <div class="ex" id="ex3" data-i18n="[style]resources.set_style"></div>
        </div>
        <div style="height: 21px;">
            <label class="lab">20--21</label>

            <div class="ex" id="ex4" data-i18n="[style]resources.set_style"></div>
        </div>
        <div style="height: 21px;">
            <label class="lab">21--22</label>

            <div class="ex" id="ex5" data-i18n="[style]resources.set_style"></div>
        </div>
        <div style="height: 21px;">
            <label class="lab">22--23</label>

            <div class="ex" id="ex6" data-i18n="[style]resources.set_style"></div>
        </div>
        <div style="height: 21px;">
            <label class="lab">23--24</label>


            <div class="ex" id="ex7" data-i18n="[style]resources.set_style"></div>
        </div>
        <div style="height: 21px;">
            <label class="lab">24--25</label>

            <div class="ex" id="ex8" data-i18n="[style]resources.set_style"></div>
        </div>
        <div style="height: 21px;">
            <label class="lab">25--26</label>

            <div class="ex" id="ex9" data-i18n="[style]resources.set_style"></div>
        </div>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,responsive,widgets.alert" src="../js/include-web.js"></script>
<script>
    var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
    var map, layer, heatMapLayer,
        url = host + "/iserver/services/map-world/rest/maps/World";

    init();

    function init() {
        if (!document.createElement('canvas').getContext) {
            document.getElementById("popupWin").style.display = "none";
            widgets.alert.showAlert(resources.msg_supportCanvas, false);
            return;
        }
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        map.addControl(new SuperMap.Control.MousePosition());
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        heatMapLayer = new SuperMap.Layer.HeatMapWeight(
            "heatMap",
            {
                "radius": 45,
                "featureWeight": "value",
                "featureRadius": "geoRadius"
            }
        );
        var items = [
            {
                start: 0,
                end: 1,
                startColor: new SuperMap.REST.ServerColor(170, 240, 233),
                endColor: new SuperMap.REST.ServerColor(180, 245, 185)
            },
            {
                start: 1,
                end: 2,
                startColor: new SuperMap.REST.ServerColor(180, 245, 185),
                endColor: new SuperMap.REST.ServerColor(223, 250, 177)
            },
            {
                start: 2,
                end: 3,
                startColor: new SuperMap.REST.ServerColor(223, 250, 177),
                endColor: new SuperMap.REST.ServerColor(224, 239, 152)
            },
            {
                start: 3,
                end: 4,
                startColor: new SuperMap.REST.ServerColor(224, 239, 152),
                endColor: new SuperMap.REST.ServerColor(160, 213, 103)
            },
            {
                start: 4,
                end: 5,
                startColor: new SuperMap.REST.ServerColor(160, 213, 103),
                endColor: new SuperMap.REST.ServerColor(44, 104, 50)
            },
            {
                start: 5,
                end: 6,
                startColor: new SuperMap.REST.ServerColor(44, 104, 50),
                endColor: new SuperMap.REST.ServerColor(29, 135, 59)
            },
            {
                start: 6,
                end: 7,
                startColor: new SuperMap.REST.ServerColor(29, 135, 59),
                endColor: new SuperMap.REST.ServerColor(118, 154, 49)
            },
            {
                start: 7,
                end: 8,
                startColor: new SuperMap.REST.ServerColor(118, 154, 49),
                endColor: new SuperMap.REST.ServerColor(204, 175, 27)
            },
            {
                start: 8,
                end: 9,
                startColor: new SuperMap.REST.ServerColor(204, 175, 27),
                endColor: new SuperMap.REST.ServerColor(198, 63, 2)
            }

        ];
        heatMapLayer.items = items;

        layer.events.on({"layerInitialized": addLayer});
    }

    function addLayer() {
        map.addLayers([layer, heatMapLayer]);
        map.setCenter(new SuperMap.LonLat(0, 0), 0);
    }

    function createHeatPoints() {
        clearHeatPoints();
        var heatPoints = [];
        var num = parseInt(document.getElementById('heatNums').value);
        var radius = parseInt(document.getElementById('heatradius').value);

        var unit = document.getElementById("radiusUnit").value,
            useGeoRadius = false;
        if ("degree" == unit) {
            useGeoRadius = true;
        }
        heatMapLayer.radius = radius
        for (var i = 0; i < num; i++) {
            heatPoints[i] = new SuperMap.Feature.Vector(
                new SuperMap.Geometry.Point(
                    Math.random() * 360 - 180,
                    Math.random() * 180 - 90
                ),
                {
                    "value": Math.random() * 9,
                    "geoRadius": useGeoRadius ? radius : null
                }
            );
        }
        heatMapLayer.addFeatures(heatPoints);
    }

    function clearHeatPoints() {
        heatMapLayer.removeAllFeatures();
    }

</script>

</body>
</html>